from client.match import ste_match
from client.match.ttypes import User

from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

from sys import stdin

def work(op, user, info):
    # Make socket
    transport = TSocket.TSocket('localhost', 9090)

    # Buffering is critical. Raw sockets are very slow
    transport = TTransport.TBufferedTransport(transport)

    # Wrap in a protocol
    protocol = TBinaryProtocol.TBinaryProtocol(transport)

    # Create a client to use the protocol encoder
    client = ste_match.Client(protocol)

    # Connect!
    transport.open()
    
    if op == "add":
        client.add_user(user, info)
    elif op == "remove":
        client.remove_user(user, info)

    # Close!
    transport.close()

def main():
    for input_str in stdin:
        op, idx, name, score = input_str.split()
        user = User(int(idx), name, int(score))
        work(op, user, "hh")

if __name__ == "__main__":
    main()
